import request from '@/utils/request'
import Qs from 'qs'

// 获取当前租户拥有的资源组
export function currentTenantApiPermGroup() {
  return request({
    url: '/sys/perm/queryApiPermOfTenant',
    method: 'get'
  })
}

// 获取api接口列表
export function listApi() {
  return request({
    url: '/sys/userAuth/listApi',
    method: 'get'
  })
}

// 获取角色类型
export function listRoleType() {
  return request({
    url: '/sys/role/queryRoleType',
    method: 'get'
  })
}

// 获取角色列表
export function listRole(data) {
  return request({
    url: '/sys/role/listRole',
    method: 'get',
    params: data
  })
}

// 删除角色
export function removeRoles(data) {
  return request({
    url: '/sys/role/removeRoles',
    method: 'delete',
    params: {
      roleIds: data
    },
    paramsSerializer: params => {
      return Qs.stringify(params, { indices: false })
    }
  })
}

// 获取权限组
export function getPermGroup(data) {
  return request({
    url: '/sys/perm/queryPermGroup',
    method: 'get',
    params: data
  })
}

// 获取角色组
export function getRoleGroup(data) {
  return request({
    url: '/sys/role/getRoleGroup',
    method: 'get',
    params: data
  })
}

// 创建角色
export function createRole(data) {
  return request({
    url: '/sys/role/createRole',
    method: 'post',
    data
  })
}

// 获取角色资源组（权限和权限实体）
export function listResGroup(data) {
  return request({
    url: '/sys/perm/queryResGroup',
    method: 'get',
    params: data
  })
}

// 删除资源数据
export function removeRes(data) {
  return request({
    url: '/sys/perm/removePermEntity',
    method: 'delete',
    params: {
      permId: data.permId,
      entityIds: data.entityIds
    },
    paramsSerializer: params => {
      return Qs.stringify(params, { indices: false })
    }
  })
}

// 获取角色创建人列表
export function listCreateTenantOfRole() {
  return request({
    url: '/sys/role/queryCreatTenantOfRole',
    method: 'get'
  })
}

// 查询api角色列表
export function listApiRole() {
  return request({
    url: '/sys/role/queryApiRole',
    method: 'get'
  })
}

// 查询api权限创建人列表
export function listCreateTenantOfApiPerm() {
  return request({
    url: '/sys/perm/queryCreateTenantOfApiPerm',
    method: 'get'
  })
}

// 查询api权限列表
export function listApiPerm(data) {
  return request({
    url: '/sys/perm/listApiPerm',
    method: 'get',
    params: data
  })
}

// 通过id删除api权限
export function removeApiPerm(data) {
  return request({
    url: '/sys/perm/removeApiPerm',
    method: 'delete',
    params: {
      permIds: data
    },
    paramsSerializer: params => {
      return Qs.stringify(params, { indices: false })
    }
  })
}